import axios from 'axios'
import { getToken } from '../utils/auth'

const instance = axios.create({
    baseURL: 'http://localhost:5000/',
    timeout: 5000
});

instance.interceptors.request.use(
    (config) => {
        console.log(config);
        let token = getToken();
        if (token) {
            config.headers['Authorization'] = 'Barear' + token
        }
        return config
    }, (err) => {
        console.log(err);

        return Promise.reject(err)
    }
)

instance.interceptors.response.use(
    (response) => {
        console.log(response);
        return response
    }, (err) => {
        console.log(err);
        return Promise.reject(err)
    }
)

export default instance